package time;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class DateTimeFormatterTest {
    public static void main(String[] args) {
        method1();
        method2();
        method3();
    }

    private static void method3() {
        DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime parse = LocalDateTime.parse("2020-03-20 15:32:34", dtf);
        System.out.println("parse = " + parse);
    }

    private static void method2() {
        LocalDateTime now = LocalDateTime.now();
        DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String format = now.format(dtf);
        System.out.println("format = " + format);
    }

    private static void method1() {
        LocalDateTime now = LocalDateTime.now();
        //JDK自带时间格式
        DateTimeFormatter dtf = DateTimeFormatter.ISO_DATE_TIME;
        String format = now.format(dtf);
        System.out.println("format = " + format);
    }
}
